package com.palfund.pagertabstrip;

import android.graphics.Color;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
        PagerTabStrip pagerTabStrip = (PagerTabStrip) findViewById(R.id.pagerTabStrip);
        pagerTabStrip.setBackgroundColor(Color.WHITE);
        pagerTabStrip.setTextColor(Color.BLACK);
        pagerTabStrip.setTabIndicatorColor(Color.RED);
        pagerTabStrip.setDrawFullUnderline(true);

        String[] titles = getResources().getStringArray(R.array.arrTabTitles);
        ArrayList<BlankFragment> list = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            BlankFragment blankFragment = BlankFragment.newInstance(i);
            list.add(blankFragment);
        }
        BlankFragmentPagerAdapter adapter = new BlankFragmentPagerAdapter
                (getSupportFragmentManager(), list, titles);
        viewPager.setAdapter(adapter);
        // 设置预览的数量
        viewPager.setOffscreenPageLimit(1);
    }
}
